package com.kanshu.ksgb.fastread.doudou.module.personal.dialog;

import android.content.Context;
import android.widget.ImageView;

import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.common.imageloader.GlideImageConfig;
import com.kanshu.ksgb.fastread.doudou.common.imageloader.GlideImageLoader;
import com.kanshu.ksgb.fastread.doudou.common.urlrouter.UrlRouter;
import com.kanshu.ksgb.fastread.doudou.common.util.DisplayUtils;
import com.kanshu.ksgb.fastread.doudou.common.versioncheck.BaseDialog;

public class DialogCreator {

    //每日弹窗
    public static BaseDialog getEveryDayDialog(Context context, String img_url, String jump_url) {
        BaseDialog baseDialog = new BaseDialog(context, R.style.dialog_style, R.layout.dialog_every_day);
        baseDialog.setCanceledOnTouchOutside(true);
        baseDialog.findViewById(R.id.close).setOnClickListener(v -> baseDialog.cancel());
        ImageView ivContent = baseDialog.findViewById(R.id.ivContent);

        GlideImageConfig config = new GlideImageConfig.Builder().
                setRoundedRadius(DisplayUtils.dip2px(context, 7)).
                setCropType(GlideImageConfig.CENTER_CROP).
                setAsBitmap(true).
                setPlaceHolderResId(R.mipmap.ic_default_pic).
                setErrorResId(R.mipmap.ic_default_pic).
                setAnimResId(R.anim.fade_out).
                setDiskCacheStrategy(GlideImageConfig.DiskCache.ALL).
                setPriority(GlideImageConfig.LoadPriority.NORMAL).build();

        GlideImageLoader.load(img_url, ivContent, config);
        ivContent.setOnClickListener(v -> {
            UrlRouter.from(context).jump(jump_url);
            baseDialog.cancel();
        });

        return baseDialog;
    }

}
